package com.leviassaf.androidbasics;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Email extends Activity implements android.view.View.OnClickListener {
	EditText edtEmails, edtIntro, edtName, edtThings, edtWhat, edtOutro;
	String strEmail, strIntro, strName, strThings, strWhat, strOutro;
	Button btnSendEmail;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.email);
		setJavaRefs();
		btnSendEmail.setOnClickListener(this);

		this.setTitle(String.format("%s-%s", this.getTitle().toString(), this.getClass().getSimpleName()));
	}

	private void setJavaRefs() {
		// TODO Auto-generated method stub
		edtEmails = (EditText)findViewById(R.id.edtEmails);
		edtIntro = (EditText)findViewById(R.id.edtIntro);
		edtName = (EditText)findViewById(R.id.edtName);
		edtThings = (EditText)findViewById(R.id.edtThings);
		edtWhat = (EditText)findViewById(R.id.edtWhat);
		edtOutro = (EditText)findViewById(R.id.edtOutro);
		btnSendEmail = (Button)findViewById(R.id.btnSendEmail);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		//36
		assignTextViewsToStringVariables();
		String[] arrStrEmailAddress = {strEmail};
		String strEmailMsg = String.format("Hey %s"
				+ "I just wanted to say %s. "
				+ "Not only that but I love it when you"
				+ " %s, that just drives me crazy."
				+ "I just want to %s you. "
				+ "Well, that's all I wanted to chit-chatter "
				+ "about, oh and %s. oh and also if you get "
				+ "bored, you should check out "
				+ "www.ftv.com\nPS. I think I love you", 
				strName, strIntro, strThings, strWhat, strOutro);
		
		//37
		Intent intentEmail = new Intent(android.content.Intent.ACTION_SEND);
		intentEmail.putExtra(android.content.Intent.EXTRA_EMAIL, arrStrEmailAddress);
		intentEmail.putExtra(android.content.Intent.EXTRA_SUBJECT, "I love you");
		intentEmail.setType("plain/text");
		intentEmail.putExtra(android.content.Intent.EXTRA_TEXT, strEmailMsg);
		startActivity(intentEmail);
	}
	
	private void assignTextViewsToStringVariables(){
		strEmail = edtEmails.getText().toString();
		strIntro = edtEmails.getText().toString();
		strName = edtName.getText().toString();
		strThings = edtThings.getText().toString();
		strWhat = edtWhat.getText().toString();
		strOutro = edtOutro.getText().toString();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		finish();
	}
}
